﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.IO;
using System.Reflection;
using System.Collections;


namespace Server
{
    class ChatHandler
    {
        private Socket clientSocket;

        public ChatHandler(Socket client)
        {
            clientSocket = client;
        }
        public bool handleChat(string[] message, Dictionary<Socket, string> clientDictionary)
        {
            
            bool ret = false;
            string protocolMess;
            protocolMess = "$FRANK,CHAT," + message[3] + "," + message[4] + "," + message[5] + ",";
            byte[] sendmess = Encoding.UTF8.GetBytes(protocolMess);
            if (message[4] == "ALL")
            {
                foreach (KeyValuePair<Socket, string> kvp in clientDictionary)
                {
                    kvp.Key.Send(sendmess);
                }
                ret = true;
            }
            else
            {
                foreach (KeyValuePair<Socket, string> kvp in clientDictionary)
                {
                    if(kvp.Value.Equals(message[4]))
                    {
                        kvp.Key.Send(sendmess);
                        ret = true;
                        break;
                    }
                }
                //send to invidual person
            }

            return ret;
        }
    }
}
